package com.aijk.ehm.api;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.exception.ErrorCodeException;

import com.aijk.commons.mijo.utils.PojoUtil;
import com.aijk.ehm.model.BasUser;
import com.aijk.ehm.model.EhmResident;
import com.aijk.ehm.model.dto.EhmResidentDto;
import com.aijk.ehm.model.qo.EhmResidentQo;
import com.aijk.ehm.model.vo.BasUserVo;
import com.aijk.ehm.model.vo.EhmResidentVo;
import com.aijk.ehm.service.EhmResidentService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("ehmResidentApiImpl")
@Transactional
public class EhmResidentApiImpl implements EhmResidentApi {
    private static Logger logger = LoggerFactory.getLogger(EhmResidentApiImpl.class);

    @Autowired
    private EhmResidentService service;

    @Override
    public Long save(EhmResident bean) throws ErrorCodeException {
        service.save(bean);
        return bean.getId();
    }

    @Override
    public int update(EhmResident bean) throws ErrorCodeException {
      return  service.update(bean);
    }

    @Override
    public EhmResidentVo findOne(Long id) throws ErrorCodeException {
        return PojoUtil.convert(service.findOne(id) , EhmResidentVo.class);
    }

    @Override
    public List<EhmResidentVo> list(EhmResidentQo qo) {
        return PojoUtil.convert(service.find(qo) , EhmResidentVo.class);
    }

    @Override
    public void deleteById(Long id) throws ErrorCodeException {
        service.delete(id);
    }

    @Override
    public int count(EhmResidentQo qo) {
        return service.count(qo);
    }

    @Override
    public PageInfo<EhmResidentVo> page(EhmResidentQo qo) {
        PagingRequest pagingRequest = new PagingRequest(qo.getPageNo().intValue(), qo.getPageSize().intValue());
        PageInfo<EhmResident> pagelist = service.page(pagingRequest,qo);
        PageInfo<EhmResidentVo> pagelistvo = PojoUtil.convert(pagelist, PageInfo.class);
        List<EhmResident> list = pagelist.getList();
        List<EhmResidentVo> listvo = PojoUtil.convert(list, EhmResidentVo.class);
        pagelistvo.setList(listvo);
        return pagelistvo;
    }

    @Override
    public int updateDeptName(EhmResident bean, EhmResidentQo qo) throws ErrorCodeException {
        return service.updateDeptName(bean , qo);
    }
}